package wwy.Controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import wwy.Common.LogicController;
import wwy.Dao.UserDao;
import wwy.Dto.LoginDto;
import wwy.Dto.RegisterDto;
import wwy.Dto.UserDto;
import wwy.Service.UserService;
import wwy.entity.User;

@RestController
@Tag(name = "用户服务")
@RequestMapping("/user")
@RefreshScope
public class UserController extends LogicController<UserService, UserDao, User, Long> {
    public UserController(UserService userService) {
        super(userService);
    }

    @PostMapping("/getUserInfo")
    @Operation(summary = "根据用户电话和密码获取用户信息(登录)")
    public UserDto getUserInfo(@RequestBody LoginDto loginDto){
        return service.getUserInfo(loginDto.getPhone(), loginDto.getPassWord());
    }

    @PostMapping("/addNewUser")
    @Operation(summary = "添加新用户(注册)")
    public String addNewUser(@RequestBody RegisterDto userInfo){
        return service.addNewUser(userInfo);
    }

    @GetMapping("/getUserByUserId/{userId}")
    @Operation(summary = "根据用户id获取用户信息")
    public UserDto getUserById(@PathVariable("userId") Long userId){
        return service.getUserById(userId);
    }
}
